package com.zhang;

public class CyclicBarrier {
    public static void main(String[] args) {
        java.util.concurrent.CyclicBarrier cyclicBarrier = new java.util.concurrent.CyclicBarrier(7,()->{
            System.out.println("****收集7颗龙珠完毕****召唤神龙！");
        });

        for (int i = 1; i <=7 ; i++) {
            final int tempInt = i;
            new Thread(()->{
                System.out.println("线程："+Thread.currentThread().getName()+"\t收集到第"+tempInt+"颗龙珠！");
                try {
                    cyclicBarrier.await();
                }catch (Exception e){
                    e.printStackTrace();
                }
            },String.valueOf(i)).start();

        }
    }
}
